﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class FinanceCenter_AddMoney : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.lbUserName.Text = _User.RealityName;

            long ToUserID = ShoveEL._Convert.StrToLong(Request["id"], -1);
            if (ToUserID > 0)
            {
                User tu = new User();
                tu.ID = ToUserID;

                string Return = "";
                int Result = tu.GetUserInfoByID(ref Return);

                if (Result != 0)
                {
                    ShoveEL._Web.JavaScript.Alert(this.Page, Return);

                    return;
                }

                tbUserName.Text = tu.Name;
                tbMemo.Text = _User.Name + "为" + tu.Name + "充值";
            }

            this.ibSubmit.Attributes.Add("onclick", "return confirm('" + System.Web.HttpUtility.HtmlEncode("您确信输入的数据无误，并且立即充值吗？") + "');");
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestCompetences = Competences.BuildCompetencesList(Competences.Finance);
        RequestLoginPage = "FinanceCenter/AddMoney.aspx";

        base.OnInit(e);
    }

    #endregion

    protected void ibSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (tbUserName.Text.Trim() == "")
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "请输入消费ID。");
            return;
        }

        //只能输入100的倍数
        double Money = ShoveEL._Convert.StrToDouble(tbMoney.Text, 0);

        if (Money == 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "请输入正确的充值金额。");
            return;
        }

        if ((Money % 100) != 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "充值金额只能是100的倍数。");
            return;
        }

        this.tbMemo.Text = _User.RealityName + "为" + tbUserName.Text + "手动充值";

        User tu = new User();
        tu.Name = ShoveEL._Convert.ToDBC(tbUserName.Text.Trim());
        string Return = "";
        int Result = tu.GetUserInfoByName(ref Return);
        if (Result != 0)
        {            
            ShoveEL._Web.JavaScript.Alert(this.Page, Return);

            return;
        }

        string ReturnDescription = "";
        Result = tu.AddBalanceManual(Money, "", _User.ID, ref ReturnDescription);
        if (Result != 0)
        {            
            ShoveEL._Web.JavaScript.Alert(this.Page, Return);

            return;
        }        

        if (tu.ID == _User.ID)
        {
            _User.GetUserInfoByID(ref Return);
        }

        tbUserName.Text = "";
        tbMoney.Text = "";

        //写入操作日志
        OperationLog Log = new OperationLog();

        Log._Memo = _User.Name + "为" + tu.Name + "手工充入" + Money.ToString() + "元";
        Log._OpDateTime = DateTime.Now;
        Log._UserID = _User.ID;
        Log._UserIP = System.Web.HttpContext.Current.Request.UserHostAddress;

        Log.Add();
        //操作日志写入完成


        ShoveEL._Web.JavaScript.Alert(this.Page, "充值成功!!!!");
    }

    protected void ibCencel_Click(object sender, ImageClickEventArgs e)
    {
        this.tbUserName.Text = string.Empty;
        this.tbMoney.Text = string.Empty;
        //this.tbMemo.Text = _User.RealityName + "为";
    }
}
